package cn.com.bsoft.cloud.model

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonSerializer
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize

@JsonSerialize(using = LoginInfoTypeSerializer::class)
@JsonDeserialize(using = LoginInfoTypeDeserializer::class)
enum class LoginInfoType(val title:String){
    MobilePhone("mobilePhone"),
    Alipay("alipay"),
    WeChat("weChat"),
    EShimin("eShimin");

    companion object {
        fun fromString(v:String?):LoginInfoType?{
            LoginInfoType.values().forEach {
                if (it.title == v) return it
            }

            return null
        }
    }
}

class LoginInfoTypeSerializer: JsonSerializer<LoginInfoType>(){
    override fun serialize(v: LoginInfoType?, g: JsonGenerator?, p: SerializerProvider?) {
        g?.writeString(v?.title)
    }
}

class LoginInfoTypeDeserializer: JsonDeserializer<LoginInfoType>(){
    override fun deserialize(p: JsonParser?, c: DeserializationContext?): LoginInfoType? {
        val v = p?.readValueAs(String::class.java)
        return LoginInfoType.fromString(v)
    }
}

class QueryUserInfoForOAuthReq{

    /*weChat alipay */
    var domain:LoginInfoType? = null

    var orgID:String? = null

    var token:String? = null

    var refresh:Boolean? = null

    var appID:String? = null

    var params:Map<String,String> = HashMap()
}

class QueryLoginInfoReq{
    /*身份。可以是用户名，邮件，手机号码等等，用来标识一个登录主体身份*/
    var principals:String? = null

    /*凭证。常见有密码，数字证书,openUserID 等等。*/
    var credentials:String? = null

    var domain:LoginInfoType? = null

    var params:Map<String,String> = HashMap()
    //var appID:String? = null
}

class BindLoginInfoReq{
    var username:String? = null

    /*身份。可以是用户名，邮件，手机号码等等，用来标识一个登录主体身份*/
    var principals:String? = null

    /*凭证。常见有密码，数字证书,openUserID 等等。*/
    var credentials:String? = null

    var domain:LoginInfoType? = null

    var vaildCode:String? = null
}

class RemoveLoginInfoReq{
    /*身份。可以是用户名，邮件，手机号码等等，用来标识一个登录主体身份*/
    var principals:String? = null

    var domain:LoginInfoType? = null
}

class LoginInfoRsp{
    var username:String? = null

    /*身份。可以是用户名，邮件，手机号码等等，用来标识一个登录主体身份*/
    var principals:String? = null

    /*凭证。常见有密码，数字证书,openUserID 等等。*/
    var credentials:String? = null

    var domain:LoginInfoType? = null

    /*第三方应用昵称*/
    var nickName:String? = null

    /*第三方应用头像*/
    var avatar:String? = null

    var attatch:String? = null

    var raw:Any? = null
}

class SendMPMessageReq{
    var sellerCode:String? = null
    var templateID: String? = null
    var openUserID: String? = null
    var url:String? = null
    var content: Map<String, Any?>?= null
}